package org.elfen.sys.service;

import org.elfen.common.util.DataUtil;
import org.elfen.sys.biz.SysUserBiz;
import org.elfen.sys.entity.SysUser;
import org.elfen.sys.facade.SysUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 系统用户服务提供者:
 * 	POST来实现“增改”，GET来实现“删查”
 */
@RestController
//@RequestMapping(SysUserService.prefixPath)
public class SysUserServiceImpl implements SysUserService{
	private static final Logger log = LoggerFactory.getLogger(SysUserServiceImpl.class);
	@Autowired
	private DiscoveryClient client;
	@Autowired
	private SysUserBiz sysUserBiz;
	
	@Override
	public String hello(String name) {
		System.out.println("接收到的参数：name="+name);
		ServiceInstance instance = client.getLocalServiceInstance();
		System.out.println("ServiceId="+instance.getServiceId()+"，Host:"+instance.getHost()+"，Port="+instance.getPort()+"，Uri="+instance.getUri());
		return "hello,"+name;
	}
	@Override
	public SysUser insert(SysUser sysUser) {
		log.debug("插入到数据库之前的对象："+sysUser);
		sysUserBiz.insert(sysUser);
		log.debug("插入到数据库之后的对象："+sysUser);
		return sysUser;
	}
	@Override
	public boolean deleteById(String id) {
		log.debug("接收到的参数："+id);
		return sysUserBiz.deleteById(id);
	}
	@Override
	public boolean flagDeleteById(String id) {
		log.debug("接收到的参数："+id);
		SysUser entity = sysUserBiz.selectById(id);
		if(DataUtil.isNotEmpty(entity)){
			entity.setIsDelete(1);
			return sysUserBiz.updateById(entity);
		}
		
		log.debug("id="+id+" 对应的记录不存在，无法执行删除操作！");
		return false;
	}
	@Override
	public SysUser updateById(SysUser sysUser) {
		log.debug("更新到数据库之前的对象："+sysUser);
		sysUserBiz.updateById(sysUser);
		log.debug("更新到数据库之后的对象："+sysUser);
		return sysUser;
	}
	@Override
	public SysUser selectById(String id) {
		log.debug("接收到的参数："+id);
		return sysUserBiz.selectById(id);
	}
	@Override
	public SysUser selectOne(SysUser sysUser) {
		sysUser = sysUserBiz.selectOne(sysUser.bindingQueryWrapper());
		return sysUser;
	}
	
}
